package com.sgb.jicai.view.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.sgb.jicai.BR;
import com.sgb.jicai.R;
import com.sgb.jicai.entity.JiCaiRequireEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import java.util.List;

/**
 * 报价规则、加盟规则，组装成列表数据展示
 */
public class JiCaiRequireAdapter extends BaseRecycleAdapter<JiCaiRequireEntity> {
    private Context context;


    public JiCaiRequireAdapter(Context context, List<JiCaiRequireEntity> datas) {
        super(context, R.layout.item_jicai_required, datas);
        this.context = context;
    }

    @Override
    public void convert(ItemViewHolder holder, JiCaiRequireEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView tvDesc = holder.getItem().findViewById(R.id.tv_desc);
        TextView tvPackUp = holder.getItem().findViewById(R.id.tv_pack_up);

        initView(tvDesc, tvPackUp);
//        MToast.showToast(context,tvDesc.getLayout().getLineCount());
    }


    private void initView(TextView tvDesc, TextView tvPackUp) {
        tvPackUp.setText("收起");
        tvPackUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (tvPackUp.getText().equals("收起")) {
                    tvPackUp.setText("展开");
                    tvDesc.setSingleLine(true);
                    tvDesc.setEllipsize(TextUtils.TruncateAt.END);
                } else {
                    tvPackUp.setText("收起");
                    tvDesc.setSingleLine(false);
                    tvDesc.setEllipsize(null);
                    tvDesc.setMaxLines(100);
                }

//                svFullContent.post(new Runnable() {
//                    @Override
//                    public void run() {
//                        svFullContent.fullScroll(View.FOCUS_DOWN);
//                    }
//                });
            }
        });

    }


}